package org.teremail.message;

public class SimpleMessage implements Message, ContentEntity {

    private final MessageHeaders header;
    private final ContentHeaders contentHeader;
    private final Content content;
    private final String id;

    public SimpleMessage(MessageHeaders header, ContentHeaders contentHeader, Content content) {
        this(Entity.UNSAVED_ID, contentHeader, header, content);
    }

    public SimpleMessage(String id, ContentHeaders contentHeader,
            MessageHeaders header, Content content) {
        this.id = id;
        this.header = header;
        this.contentHeader = contentHeader;
        this.content = content;
    }

    public ContentHeaders getContentHeader() {
        return contentHeader;
    }

    public MessageHeaders getHeader() {
        return header;
    }

    public Content getContent() {
        return content;
    }

    public String getId() {
        return id;
    }

    public EntityType getType() {
        return EntityType.SIMPLE_MESSAGE;
    }
    
    public void accept(EntityVisitor v) {
        v.visitSimpleMessage(this);
    }

    /**
     * @see org.teremail.message.Message#isMultipart()
     */
    public boolean isMultipart() {
        String contentType = header.getString("Content-Type");
        return contentType != null && contentType.startsWith("multipart/");
    }
}
